package com.ruoyi.business.controller;

import java.util.List;

import com.ruoyi.business.domain.vo.BusCollectionItemVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.BusCollectionItem;
import com.ruoyi.business.service.IBusCollectionItemService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采集项Controller
 * 
 * @author asher
 * @date 2021-11-03
 */
@RestController
@RequestMapping("/business/collection_item")
public class BusCollectionItemController extends BaseController
{
    @Autowired
    private IBusCollectionItemService busCollectionItemService;

    /**
     * 查询采集项列表
     */
    @PreAuthorize("@ss.hasPermi('business:collection_item:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusCollectionItem busCollectionItem)
    {
        startPage();
        List<BusCollectionItemVO> list = busCollectionItemService.selectBusCollectionItemDeepList(busCollectionItem);
        return getDataTable(list);
    }

    /**
     * 导出采集项列表
     */
    @PreAuthorize("@ss.hasPermi('business:collection_item:export')")
    @Log(title = "采集项", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BusCollectionItem busCollectionItem)
    {
        List<BusCollectionItem> list = busCollectionItemService.selectBusCollectionItemList(busCollectionItem);
        ExcelUtil<BusCollectionItem> util = new ExcelUtil<BusCollectionItem>(BusCollectionItem.class);
        return util.exportExcel(list, "采集项数据");
    }

    /**
     * 获取采集项详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:collection_item:query')")
    @GetMapping(value = "/{collectionItemId}")
    public AjaxResult getInfo(@PathVariable("collectionItemId") Long collectionItemId)
    {
        return AjaxResult.success(busCollectionItemService.selectBusCollectionItemByCollectionItemId(collectionItemId));
    }

    /**
     * 新增采集项
     */
    @PreAuthorize("@ss.hasPermi('business:collection_item:add')")
    @Log(title = "采集项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusCollectionItem busCollectionItem)
    {
        return toAjax(busCollectionItemService.insertBusCollectionItem(busCollectionItem));
    }

    /**
     * 修改采集项
     */
    @PreAuthorize("@ss.hasPermi('business:collection_item:edit')")
    @Log(title = "采集项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusCollectionItem busCollectionItem)
    {
        return toAjax(busCollectionItemService.updateBusCollectionItem(busCollectionItem));
    }

    /**
     * 删除采集项
     */
    @PreAuthorize("@ss.hasPermi('business:collection_item:remove')")
    @Log(title = "采集项", businessType = BusinessType.DELETE)
	@DeleteMapping("/{collectionItemIds}")
    public AjaxResult remove(@PathVariable Long[] collectionItemIds)
    {
        return toAjax(busCollectionItemService.deleteBusCollectionItemByCollectionItemIds(collectionItemIds));
    }
}
